package com.system.enterprisemanagementsystem.controller;

import com.system.enterprisemanagementsystem.anno.LogOperation;
import com.system.enterprisemanagementsystem.pojo.Emp;
import com.system.enterprisemanagementsystem.pojo.EmpQueryParam;
import com.system.enterprisemanagementsystem.pojo.PageResult;
import com.system.enterprisemanagementsystem.pojo.Result;
import com.system.enterprisemanagementsystem.service.EmpService;
import com.system.enterprisemanagementsystem.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 员工管理
 */
@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {

    @Autowired
    EmpService empService;

    @GetMapping
    public Result page(EmpQueryParam empQueryParam) {
        log.info("查询请求参数： {}", empQueryParam);
        PageResult pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 查询全部员工
     * @return
     */
    @GetMapping("/list")
    public Result findAll() {
        log.info("查询全部员工");
        List<Emp> empList = empService.getAllEmp();
        return Result.success(empList);
    }
    /**
     * 添加员工
     */
    @PostMapping
    @LogOperation
    public Result save(@RequestBody Emp emp){
        log.info("请求参数emp: {}", emp);
        empService.save(emp);
        return Result.success();
    }

    /**
     * 删除员工
     * @param ids
     * @return
     */
    @DeleteMapping
    @LogOperation
    public Result deleteEmps(@RequestParam List<Integer> ids){

        log.info("批量删除员工数据ids：{}",ids);
        empService.delteByIds(ids);
        return Result.success();
    }

    /**
     * 查询回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id){
        log.info("根据id查询员工数据、回显id:{}",id);
        Emp emp =empService.queryById(id);
        return Result.success(emp);
    }

    /**
     修改用户数据
     * @param emp
     */
    @PutMapping
    @LogOperation
    public Result updateEmp(@RequestBody Emp emp){
        log.info("根据传来的数据修改用户信息emp:{}",emp);
        empService.updateEmp(emp);
        return Result.success();
    }

}
